<template>
  <!-- 维护作业-重填单受理维护页面 -->
  <div class="fillcontain">
    <el-form :model="searchParams" ref="ruleForm" label-width="100px" class="search_container">
      <el-row>
        <el-col :span="4" class="pt5">
          <el-radio-group v-model="searchParams.flag02">
            <el-radio label="">全部</el-radio>
            <el-radio label="N">未处理</el-radio>
          </el-radio-group>
        </el-col>
        <el-col :span="6" class="text_left">
          <el-button type="primary" icon="el-icon-search" @click="subGetList"></el-button>
          <el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
        </el-col>
      </el-row>
    </el-form>
    <div class="contain">
      <el-row class="bgfff pb15 pt15">
        <el-col :span="24" class="pt5">
          <el-button type="danger" plain @click="addClick">新增</el-button>
        </el-col>
      </el-row>
      <!-- 查询结果 -->
      <div class="table_container">
        <el-table
            v-loading="loading"
            :data="tableData"
            highlight-current-row
            header-cell-class-name="table-header-class"
            style="width:100%">
          <el-table-column
              min-width="120"
              property="chdrcoy"
              label="公司"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="applnum01"
              label="新受理号"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="chdrnum"
              label="原保单号"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="applnum02"
              label="原受理号"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="fieldType"
              label="类型"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="surname"
              label="被保人姓名"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="flag01"
              label="Relndex完成"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="userid01"
              label="复核人员"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="dateup01"
              label="处理日期"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="flag02"
              label="核保处理完成"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="userid02"
              label="核保人员"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="dateup02"
              label="完成日期"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              fixed="right"
              min-width="120"
              label="操作"
              align='center'>
            <template slot-scope="scope">
              <!-- <el-button type="text" size="small" @click="modifyClick(scope.row)">修改</el-button> -->
              <span class="operationIcon" @click="modifyClick(scope.row)">
                <el-tooltip class="item" effect="light" content="修改" placement="top">
                  <i class="el-icon-edit"></i>
                </el-tooltip>
              </span>
              <!--<el-button type="text" size="small" @click="deleteData(scope.row)">删除</el-button> -->
              <span class="operationIcon ml5" @click="deleteData(scope.row)">
                <el-tooltip class="item" effect="light" content="删除" placement="top">
                  <i class="el-icon-delete"></i>
                </el-tooltip>
              </span>
            </template>
          </el-table-column>
        </el-table>
        <el-row>
          <el-col :span="24">
            <div class="pagination">
              <el-pagination
                  background
                  v-if='paginations.total > 0'
                  :page-sizes="paginations.pageSizes"
                  :page-size="paginations.pageSize"
                  :layout="paginations.layout"
                  :total="paginations.total"
                  :current-page='paginations.pageIndex'
                  @current-change='handleCurrentChange'
                  @size-change='handleSizeChange'>
              </el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <!-- 弹框 修改-->
    <el-dialog
        title="修改重填单受理维护"
        :visible.sync="showDialog"
        width="50%"
        center>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12" class="common-box">
            <el-form-item label="公司" prop="chdrcoy">
              <el-input clearable v-model="form.chdrcoy" readonly placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" class="common-box">
            <el-form-item label="新受理号" prop="applnum01">
              <el-input clearable v-model="form.applnum01" :readonly="form.method != 'add'" maxlength="7"
                        placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" class="common-box">
            <el-form-item label="原保单号" prop="chdrnum">
              <el-input clearable v-model="form.chdrnum" :readonly="form.method != 'add'" maxlength="8"
                        placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" class="common-box">
            <el-form-item label="原受理号" prop="applnum02">
              <el-input clearable v-model="form.applnum02" :readonly="form.method != 'add'" maxlength="7"
                        placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" class="common-box">
            <el-form-item label="类型" prop="fieldType">
              <el-select v-model="form.fieldType" placeholder="">
                <el-option
                    v-for="item in fieldTypes"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" class="common-box">
            <el-form-item label="被保人姓名" prop="surname">
              <el-input clearable v-model="form.surname" readonly placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" class="common-box">
            <el-form-item label="Reindex完成" prop="flag01">
              <el-select v-model="form.flag01" placeholder="">
                <el-option
                    v-for="item in yesOrno"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" class="common-box">
            <el-form-item label="复核人员" prop="userid01">
              <el-input clearable v-model="form.userid01" readonly placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" class="common-box">
            <el-form-item label="核保处理完成" prop="flag02">
              <el-select v-model="form.flag02" @change="changeFlag02" placeholder="">
                <el-option
                    v-for="item in yesOrno"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" class="common-box">
            <el-form-item label="处理日期" prop="dateup01">
              <el-input clearable v-model="form.dateup01" readonly placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" class="common-box">
            <el-form-item label="核保人员" prop="userid02">
              <el-input clearable v-model="form.userid02" readonly placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" class="common-box">
            <el-form-item label="完成日期" prop="dateup02">
              <el-input clearable v-model="form.dateup02" readonly placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
                <el-button @click="saveData" class="Defaultbutton">保 存</el-button>
                <el-button @click="showDialog = false">返 回</el-button>
            </span>
    </el-dialog>
  </div>
</template>

<script>
  import {mapState, mapGetters} from 'vuex'
  import constant from '@/utils/constant';
  import * as api from '@/api/setting/maintain/refillAccepPolicyMaintenance.js';
  import validRules from "@/utils/validRules";

  export default {
    data() {
      var checkApplnum01 = (rule, value, callback) => {
        let para = {
          applnum01: value
        }
        api.queryEuaapkyVOByApplnum(para).then(res => {
          if (res.resultCode == constant.SUCCESS) {
            callback();
          } else {
            callback(new Error('无此受理号, 请重新输入!'));
          }
        }).catch(err => {
          callback(new Error('无此受理号, 请重新输入!'));
        })
      };
      var checkApplnum02 = (rule, value, callback) => {
        let para = {
          applnum02: value
        }
        api.checkOldApplnum(para).then(res => {
          if (res.resultCode == constant.SUCCESS && res.data) {
            if (res.data.chdrnum) {
              this.form.chdrnum = res.data.chdrnum; //保单号
            }
            this.form.surname = res.data.surname; //被保人
            let dealChdrnum02 = {
              chdrnum: this.form.chdrnum,  //保单号
              chdrcoy: this.form.chdrcoy,  //compamy
            }
            api.dealChdrnum(dealChdrnum02).then(res => {
              if (res.resultCode == constant.SUCCESS) {
                if (res.data && res.data.applnum02) {
                  this.form.applnum02 = res.data.applnum02; //保单号
                }
                if (res.data && res.data.surname) {
                  this.form.surname = res.data.surname; //被保人
                }
                callback();
              } else {
                callback(new Error('无此受理号, 请重新输入!'));
              }
            }).catch(err => {
              callback(new Error('无此受理号, 请重新输入!'));
            })
          } else {
            callback(new Error('无此受理号, 请重新输入!'));
          }
        }).catch(err => {
          callback(new Error('无此受理号, 请重新输入!'));
        })
      };
      return {
        valueDate: '',
        showDialog: false,//默认隐藏 修改弹框
        // 查询条件
        rules_temp: {// 缓存的校验规则，add模式启用，update模式不需要启用校验
          applnum01: [
            {required: true, message: '请输入新受理号', trigger: 'blur'},
            {len: 7, message: '新受理号为必要性栏位不可空白或长度不对, 请输入!'},
            {validator: checkApplnum01, trigger: 'blur'},
          ],
          applnum02: [
            {required: true, message: '请输入原受理号', trigger: 'blur'},
            {len: 7, message: '原受理号为必要性栏位不可空白或长度不对, 请输入!'},
            {validator: checkApplnum02, trigger: 'blur'},
          ],
          chdrnum: [
            {validator: validRules.isEnglishOrNumber, message: '请输入正确的原保单号', trigger: 'blur'}
          ]
        },
        rules: {
          applnum01: [
            {required: true, message: '请输入新受理号', trigger: 'blur'},
            {len: 7, message: '新受理号为必要性栏位不可空白或长度不对, 请输入!'},
            {validator: checkApplnum01, trigger: 'blur'},
          ],
          applnum02: [
            {required: true, message: '请输入原受理号', trigger: 'blur'},
            {len: 7, message: '原受理号为必要性栏位不可空白或长度不对, 请输入!'},
            {validator: checkApplnum02, trigger: 'blur'},
          ],
          chdrnum: [
            {validator: validRules.isEnglishOrNumber, message: '请输入正确的原保单号', trigger: 'blur'}
          ]
        },
        searchParams: {
          flag02: '',
        },
        tableData: [],
        loading: false,

        businessDate: '',
        userInfo: {},
        form: {
          chdrcoy: '',
          applnum01: '',
          chdrnum: '',
          applnum02: '',
          fieldType: '',
          surname: '',
          flag01: '',
          userid01: '',
          dateup01: '',
          flag02: '',
          userid02: '',
          dateup02: '',
        },
        fieldTypes: [
          {value: '1', label: '重填更改保单号'},
          {value: '2', label: '重填不变保单号'},
          {value: '3', label: '契撤重投新单'},
          {value: '4', label: 'Alter变更'},
        ],
        yesOrno: [
          {value: 'Y', label: 'Y'},
          {value: 'N', label: 'N'},
        ],

        //需要给分页组件传的信息
        paginations: {
          total: 0,        // 总数
          pageIndex: 1,  // 当前位于哪页
          pageSize: 10,   // 1页显示多少条
          pageSizes: [5, 10, 15, 20],  //每页显示多少条
          layout: "total, sizes, prev, pager, next, jumper"   // 翻页属性
        },
      }
    },
    created() {
//          this.getList();
      this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
      this.init();
    },
    mounted() {
      // this.getList();
    },
    methods: {
      init() {
        let para = {
          method: 'add'
        }
        api.dataInfoDeal(para).then(res => {
          this.$store.dispatch('loading/CHANGE_LOADING', false)
          if (res.resultCode == constant.SUCCESS) {
            this.chdrcoy = res.data.chdrcoy;
            this.businessDate = res.data.businessDate;
          }
        }).catch(err => {
          this.$store.dispatch('loading/CHANGE_LOADING', false);
        })
      },
      modifyClick(row) {
        this.rules = {};
        if (this.$refs['form']) {
          this.$refs['form'].resetFields();
        }
        Object.assign(this.form, row);
        this.form.method = 'modify';
        this.showDialog = true;
      },
      addClick() {
        this.rules = this.rules_temp;
        if (this.$refs['form']) {
          this.$refs['form'].resetFields();
        }
        this.form.method = 'add';
        this.$set(this.form, 'fieldType', '1');
        this.$set(this.form, 'flag01', 'N');
        this.$set(this.form, 'dateup01', '0');
        this.$set(this.form, 'flag02', 'N');
        this.$set(this.form, 'dateup02', '0');
        this.showDialog = true;
      },
      changeFlag02() {
        if (this.form.flag02 == 'Y') {
          this.form.userid02 = this.userInfo.account;
          this.form.dateup02 = this.businessDate;
        } else {
          this.form.userid02 = '';
          this.form.dateup02 = '';
        }
      },

      // 查询列表
      getList() {
        this.paginations.total = 0;
        this.tableData = [];
        let para = {
          "flag02": this.searchParams.flag02,
          "pageSize": this.paginations.pageSize,
          "pageNumber": this.paginations.pageIndex,
        }

        this.$store.dispatch('loading/CHANGE_LOADING', true)

        api.queryList(para).then(res => {
          this.$store.dispatch('loading/CHANGE_LOADING', false)
          if (res.resultCode == constant.SUCCESS) {
            if (res.data && res.data.list.length) {
              this.paginations.total = res.data.total;
              this.tableData = res.data.list;
            } else {
              this.$message({
                message: '无符合条件资料',
                type: 'error'
              })
            }
          }
        }).catch(err => {
          this.$store.dispatch('loading/CHANGE_LOADING', false);
        })
      },
      saveData() {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            this.$store.dispatch('loading/CHANGE_LOADING', true)
            api.editData(this.form).then(res => {
              this.$store.dispatch('loading/CHANGE_LOADING', false)
              if (res.resultCode == constant.SUCCESS) {
                this.$message({
                  message: '数据添加成功',
                  type: 'success'
                });
                this.showDialog = false;
                this.getList();
              }
            }).catch(err => {
              this.$store.dispatch('loading/CHANGE_LOADING', false);
            })
          }
        });
      },
      deleteData(row) {
        this.$confirm('确定删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$store.dispatch('loading/CHANGE_LOADING', true)
          let para = {
            chdrcoy: row.chdrcoy,
            applnum01: row.applnum01,
            chdrnum: row.chdrnum,
            applnum02: row.applnum02,
          }
          if (para.chdrcoy == "" && para.applnum01 == "" && para.chdrnum == "" && para.applnum02 == "") {
            this.$message.error("请选择要删除的记录！");
            return;
          }
          api.deleteData(para).then(res => {
            this.$store.dispatch('loading/CHANGE_LOADING', false)
            if (res.resultCode == constant.SUCCESS) {
              this.$message({
                message: '数据删除成功',
                type: 'success'
              });
              this.getList();
            }
          }).catch(err => {
            this.$store.dispatch('loading/CHANGE_LOADING', false);
          })
        }).catch(() => {

        });
      },
      // 每页多少条切换
      handleSizeChange(pageSize) {
        this.paginations.pageSize = pageSize;
        this.getList();
      },
      // 上下分页
      handleCurrentChange(page) {
        this.paginations.pageIndex = page;
        this.getList();
      },
      // 根据条件查询列表
      subGetList() {
        this.paginations.pageIndex = 1;
        this.getList();
      },
      // 清除查询条件
      resetSearch() {
        this.searchParams.flag02 = '';
      }
    },
    computed: {
      ...mapGetters(['tags']),
      reload() {
        return this.$store.state.loading.reload;
      }
    },
    activated() {
      if (this.reload) {
        this.$store.dispatch('loading/CHNAGE_RELOAD', false)
        Object.assign(this.$data, this.$options.data());
      }
    }
  }
</script>

<style lang="less" scoped>
  .fillcontain {
    padding-bottom: 0;
  }

  .contain {
    background: #fff;
    padding: 10px;
    margin-bottom: 20px;
  }

  .pagination {
    padding: 10px 20px;
    text-align: right;
  }

  .operationIcon {
    // padding: 12px;
    border: 1px solid #e5e5e5;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: inline-block;
    cursor: pointer;
    box-shadow: 0 0 3px #f9f9f9;
  }

  .search_container {
    padding: 20px 20px 0 20px;
    //    border-top: 1px solid #e1e1e1;
  }

  .common-box {
    padding-bottom: 15px;
  }

  .common-lab {
    line-height: normal !important;
    text-align: right;

    .labelName {
      text-align: right;
    }
  }
</style>



